//
//  BIDEMailViewController.m
//  商务厅
//
//  Created by mal on 13-12-13.
//  Copyright (c) 2013年 mal. All rights reserved.
//

#import "BIDEMailViewController.h"
#import "BIDWriteEmailViewController.h"
#import "BIDEmailInboxViewController.h"
#import "BIDEmailOutboxViewController.h"
#import "BIDEmailDraftboxViewController.h"
#import "BIDCollectionCellView.h"

//角标
static NSString *emailBadgeNumberURL = @"emailReplyAndroid!gainEmailNotRead.action";

@interface BIDEMailViewController ()

@end

@implementation BIDEMailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"内部邮件";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.titleArr = [[NSMutableArray alloc] initWithObjects:@"写邮件", @"收件箱", @"发件箱", @"草稿箱", nil];
    _menuArr = @[@{@"title":@"写邮件", @"imgName":@"email_add.png"},
                 @{@"title":@"收件箱", @"imgName":@"email_received.png"},
                 @{@"title":@"发件箱", @"imgName":@"email_sent.png"},
                 @{@"title":@"草稿箱", @"imgName":@"email_draft.png"}];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushNotificationHandler) name:PUSH_NOTIFICATION object:nil];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self refreshBadge];
}

- (void)setTheme
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSNumber *value = [userDefaults objectForKey:@"theme"];
    switch([value intValue])
    {
        case 1:
        {
            self.imgArr = [[NSMutableArray alloc] initWithObjects:@"email_add.png", @"email_received.png", @"email_sent.png", @"email_draft.png", nil];
        }
            break;
        case 2:
        {
            self.imgArr = [[NSMutableArray alloc] initWithObjects:@"email_add2.png", @"email_received2.png", @"email_sent2.png", @"email_draft2.png", nil];
        }
            break;
        case 3:
        {
            self.imgArr = [[NSMutableArray alloc] initWithObjects:@"email_add3.png", @"email_received3.png", @"email_sent3.png", @"email_draft3.png", nil];
        }
            break;
    }
}

- (void)pushNotificationHandler
{
    [self refreshBadge];
}

- (void)refreshBadge
{
    NSString *strPost = [[NSString alloc] initWithFormat:@"userId=%@", [AppDelegate getUserId]];
    NSDictionary *dictionary1 = @{@"index":@1, @"url":emailBadgeNumberURL, @"param_request":strPost, @"param_response":@"total"};
    NSArray *arr = [[NSArray alloc] initWithObjects:dictionary1, nil];
    [self getCornerMarkCount:arr];
}

- (void)backBtnHandler
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [self.navController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger index = [indexPath row];
    switch(index)
    {
        case 0:
        {
            //写邮件
            BIDWriteEmailViewController *writeEmailViewController = [[BIDWriteEmailViewController alloc] initWithNibName:@"BIDWriteEmailViewController" bundle:nil];
            [self.navigationController pushViewController:writeEmailViewController animated:YES];
        }
            break;
        case 1:
        {
            //收件箱
            BIDEmailInboxViewController *inboxViewController = [[BIDEmailInboxViewController alloc] init];
            [self.navigationController pushViewController:inboxViewController animated:YES];
        }
            break;
        case 2:
        {
            //发件箱
            BIDEmailOutboxViewController *outboxViewController = [[BIDEmailOutboxViewController alloc] init];
            [self.navigationController pushViewController:outboxViewController animated:YES];
        }
            break;
        case 3:
        {
            //草稿箱
            BIDEmailDraftboxViewController *draftboxViewController = [[BIDEmailDraftboxViewController alloc] init];
            [self.navigationController pushViewController:draftboxViewController animated:YES];
        }
            break;
    }
}

@end
